import axios from "axios";

const state = {
    articles: [],
};
const mutations = {
    setArticles(state, results) {
        state.articles = results;
    },
};
const actions = {
    async getArticles(ctx, id) {
        // 1. 请求接口
        const {
            data: {
                data: { results },
            },
        } = await axios("http://geek.itheima.net/v1_0/articles", {
            params: {
                channel_id: id,
                timestamp: Date.now(), // 获取时间戳
            },
        });
        // 2. 更新数据 -> mutations
        ctx.commit("setArticles", results);
    },
};
export default {
    namespaced: true,
    state,
    mutations,
    actions,
};
